<?php
// +----------------------------------------------------------------------
// | HkCms 路由
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2021 http://www.hkcms.cn, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 广州恒企教育科技有限公司 <admin@hkcms.cn>
// +----------------------------------------------------------------------

use think\facade\Route;

Route::pattern([
    'catdir' => '(?!addons)[A-Za-z0-9_\-]+', // 栏目的父级英文目录
    'list'   => '(?!addons)[A-Za-z0-9_\-]+', // 栏目名称
    'cid'   => '\d+',   // 栏目ID
    'id'   => '\d+',    // 文章ID
    'm'   => '[A-Za-z][A-Za-z0-9_\-]+',    // 模型标识
]);

$site = app()->cache->get('site');
if (empty($site)) {
    $site = \app\admin\model\routine\Config::initConfig();
}

// 触发路由标签位
hook('index_route');

if (!Route::getName('/index/lists') && !Route::getName('/index/show') && $site['url_mode']!=1) { // 指定列表页、详情规则时不再写入默认规则
    if ($site['url_mode']==2) { // /父目录/目录/,/父目录/目录/内容id.html
        // 列表页
        Route::rule('<catdir>/<list>/$','/index/lists')->ext('');
        Route::rule('<list>/$','/index/lists')->ext('');
        // 详情页
        Route::rule('<catdir>/<list>/<id>$','/index/show')->ext('html');
        Route::rule('<list>/<id>$','/index/show')->ext('html');
    } else if ($site['url_mode']==3) { // /目录/,/目录/内容id.html
        // 列表页
        Route::rule('<list>/$','/index/lists')->ext('');
        // 详情页
        Route::rule('<list>/<id>$','/index/show')->ext('html');
    } else if ($site['url_mode']==4) { // /模型/栏目,/模型/栏目/内容ID.html
        // 列表页
        Route::rule('<m>/<list>/$','/index/lists')->ext('');
        // 详情页
        Route::rule('<m>/<list>/<id>$','/index/show')->ext('html');
    } else if ($site['url_mode']==5) { // /目录.html，/目录/内容ID.html
        // 列表页
        Route::rule('<list>$','/index/lists')->ext('html');
        // 详情页
        Route::rule('<list>/<id>$','/index/show')->ext('html');
    }
}